package com.kc.business.service.impl;

import com.kc.business.domain.BizArtisanEnterForm;
import com.kc.business.domain.BizUser;
import com.kc.business.mapper.BizArtisanEnterMapper;
import com.kc.business.mapper.BizUserMapper;
import com.kc.business.service.IBizArtisanEnterService;
import com.kc.common.constant.BizConstants;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/9/25
 */
@Service
public class BizArtisanEnterServiceImpl implements IBizArtisanEnterService {

    @Resource
    BizArtisanEnterMapper artisanEnterMapper;
    @Resource
    BizUserMapper userMapper;

    /**
     * 匠人入驻列表
     *
     * @param artisanEnterForm
     * @return
     */
    @Override
    public List<BizArtisanEnterForm> getList(BizArtisanEnterForm artisanEnterForm) {
        return artisanEnterMapper.select(artisanEnterForm);
    }

    /**
     * 修改匠人入驻申请
     *
     * @param artisanEnterForm
     * @return
     */
    @Override
    @Transactional
    public int edit(BizArtisanEnterForm artisanEnterForm) {
        int ret = artisanEnterMapper.updateByPrimaryKeySelective(artisanEnterForm);
        if (BizConstants.PASS_VERIFY.equals(artisanEnterForm.getStatus())) {
            BizArtisanEnterForm _artisanEnterForm = artisanEnterMapper.selectByPrimaryKey(artisanEnterForm.getEnterId());
            BizUser user = new BizUser();
            user.setId(_artisanEnterForm.getUserId());
            user.setIsArtisan(BizConstants.YES);
            userMapper.updateByPrimaryKeySelective(user);
        }

        return ret;
    }
}
